Derive heading ids from source text, not smart-punctuation glyphs - #256
Merged
Conversation
The parser bakes smart punctuation into heading text (apostrophe as U+2019, `--`/`---` as en/em dash, `...` as ellipsis). Those glyphs are non-ASCII, so the slug step preserved them and they leaked into the id (e.g. id="Bob<U+2019>s-Guide"). Reverse the core smart-punctuation glyphs back to their ASCII source before slugging, so ids are derived from the source text and match the djot.js reference. Example: "# Bob's Guide" now yields id="Bob-s-Guide". Note: this changes ids for every heading containing an apostrophe, quote, or dash; links to the old glyph-bearing anchors need updating.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #256 +/- ##
=========================================
Coverage 92.35% 92.36%
- Complexity 3630 3631 +1
=========================================
Files 109 109
Lines 10253 10263 +10
=========================================
+ Hits 9469 9479 +10
Misses 784 784 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Heading auto-ids leaked smart-punctuation glyphs. The parser bakes smart punctuation into heading text (apostrophe as U+2019,
--/---as en/em dash,...as ellipsis). Those glyphs are non-ASCII, so the slug step preserved them:# Bob's Guideproducedid="Bob<U+2019>s-Guide"with a real curly apostrophe.The djot.js reference does not do this. Its
smart_punctuationnodes carry the ASCII source (',--,...) and it slugs that source, so ids never contain typographic glyphs.Fix
Reverse the core smart-punctuation glyphs back to their ASCII source in
HeadingIdTrackerbefore slugging, so ids are derived from source text and align with the reference.# Bob's GuideBob's-Guide(curly)Bob-s-Guide# a -- ba-<endash>-ba-b# Say "Hello"Say-"Hello"(curly)Say-HelloBehavior change
Every heading containing an apostrophe, quote, or dash now gets a different id, so links to the old glyph-bearing anchors need updating. This is intentional and matches the djot.js reference plus the agreed direction in jgm/djot#391 and jgm/djot#393 (strike punctuation exceptions; ids derived from source text).
Known limitation
Smart punctuation is baked into plain text nodes, so a literal author-typed typographic glyph (a real U+2013 in the source) is indistinguishable from a parser-generated one and is reversed the same way. Rare, and documented in the code and reference docs. A full fix needs node-level source tracking (follow-up).
Docs updated in
docs/reference/enhancements.md(normalization rules + examples).